/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package bean.business;

import entities.Curriculum;
import java.util.List;
import javax.ejb.Stateless;
import javax.ejb.LocalBean;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

/**
 *
 * @author HoangHai
 */
@Stateless
@LocalBean
public class curriculumBean {
    @PersistenceContext(unitName = "DeclarationBoard-ejbPU")
    private EntityManager em;

    public void persist(Object object) {
        em.persist(object);
    }

    // Add business logic below. (Right-click in editor and choose
    // "Insert Code > Add Business Method")
    public List<Curriculum> allCurriculum(){
        List<Curriculum> curriculums = em.createNamedQuery("Curriculum.findAll").getResultList();
        return curriculums;
    }
    
    public Curriculum findCurByID(int id){
        Curriculum curriculum = (Curriculum) em.createNamedQuery("Curriculum.findByCuID").setParameter("cuID", id).getSingleResult();
        return curriculum;
    }
    
    public boolean addCurriculum(Curriculum c){
        boolean flag;
        try {
            em.persist(c);
            flag = true;
        } catch (Exception e) {
            flag = false;
        }
        return flag;
    }
    
    public boolean updateCurriculum(Curriculum c){
        boolean flag;
        try {
            em.merge(c);
            flag = true;
        } catch (Exception e) {
            flag = false;
        }
        return flag;
    }
    
    public boolean delCurriculum(int id){
        boolean flag;
        try {
            Curriculum c = findCurByID(id);
            em.remove(c);
            flag = true;
        } catch (Exception e) {
            flag = false;
        }
        return flag;
    }
}
